/*引入dgram模块*/
var dgram=require('dgram')
/*存放client信息*/
var clients= new Array();
/*创建UDP服务器*/
var serve=dgram.createSocket('udp4',function (msg,rinfo){
          /*将用户加入到数组中*/
          console.log(msg.toString());
          if(clients.indexOf(rinfo.address.toString()+'-'+rinfo.port.toString())<0){
                clients.push(rinfo.address.toString()+'-'+rinfo.port.toString());
                console.log('put...');
          }
          clients.forEach(function (item) {
                 if(item!=rinfo.address.toString()+'-'+rinfo.port.toString()){
                     var message=item+':'+msg.toString();
                     var lp= item.split('-');
                     serve.send(message,0,message.length,lp[1],lp[0],function (err, bytes) {
                         if(err){
                             console.log(err);
                             return;
                         }
                         console.log(rinfo.address.toString()+'-'+rinfo.port.toString(),bytes)
                     })
                 }
          });
});
serve.bind(8888,'localhost',function () {
      console.log('bind 8888')
})